package com.service.admin.member.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.service.admin.member.controller.rep.MemberPgeRep;
import com.service.admin.member.controller.req.AuditMemberVerifyReq;
import com.service.admin.member.controller.req.AuditQueryPageReq;
import com.service.admin.member.service.MemberVerifiedService;
import com.service.core.rest.response.CommonPageRep;
import com.service.dao.mapper.MemberVerifiedMapper;
import com.service.dao.model.Member;
import com.service.dao.model.MemberVerified;
import com.service.dao.po.MemberVerifyPO;
import com.service.utility.modelmapper.ModelMapperUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class MemberVerifiedServiceImpl extends ServiceImpl<MemberVerifiedMapper, MemberVerified> implements MemberVerifiedService {


	@Override
	public CommonPageRep<MemberPgeRep> pageAudit(AuditQueryPageReq auditQueryPageReq) {
		Page<MemberVerifyPO> page = PageHelper.startPage(auditQueryPageReq.getPageNo(), auditQueryPageReq.getPageSize());
		baseMapper.selectByFilter(auditQueryPageReq.getUserAccount(), auditQueryPageReq.getVerifyStatus().getCode());
		List<MemberPgeRep> resultList = page.getResult().stream()
				.map(x -> ModelMapperUtil.getStrictModelMapper().map(x, MemberPgeRep.class)).collect(Collectors.toList());
		return CommonPageRep.buildResultRep(page, resultList);
	}
	/**
	 * 审核用户实名认证
	 *
	 * @param req
	 * @return
	 */
	@Override
	public boolean auditVerifyStatus(AuditMemberVerifyReq req) {
		MemberVerified memberVerified = baseMapper.selectById(req.getMemberId());
		if(ObjectUtils.isEmpty(memberVerified)){
			return false;
		}else{
			memberVerified.setVerifyStatus(req.getVerifyStatus().getCode());
			memberVerified.setRemake(req.getRemake());
			return baseMapper.updateById(memberVerified) > 0;
		}
	}
}
